<?php

namespace App\Admin\Controllers;

use App\Models\Family;
use App\Models\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class UserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new User(), function (Grid $grid) {
            $grid->column('name');
            $grid->column('mobile');
            $grid->column('gender')->using(config('option.gender'))->label(config('option.radio_option_color'));
            $grid->column('identity_type')->using(config('option.identity_type'));
            $grid->column('household')->using(config('option.radio_option'))->label(config('option.radio_option_color'));
            $grid->column('is_move_out')->using(config('option.radio_option'))->label(config('option.radio_option_color'));
            $grid->column('is_foreign')->using(config('option.radio_option'))->label(config('option.radio_option_color'));
            $grid->column('is_married')->using(config('option.married_option'))->label(config('option.radio_option_color'));


            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('identity_type')->select(config('option.identity_type'))->width(3);
                $filter->equal('is_move_out')->select(config('option.radio_option'))->width(3);
                $filter->equal('is_married')->select(config('option.married_option'))->width(3);
            });
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {

        return Form::make(new User(), function (Form $form) {
            $form->column(6, function (Form $form) {
                $form->text('name')->required();
                $form->email('email');
                $form->text('mobile')->type('number');
                $form->radio('gender')->options(config('option.gender'))->default(1);
                $form->password('password');
            });
            $form->column(6, function (Form $form) {
                $form->select('identity_type')->options(config('option.identity_type'))->default(1);
                $form->radio('household')->options(config('option.radio_option'))->default(2);
                $form->radio('is_die')->options(config('option.radio_option'))->default(2);
                $form->radio('is_move_out')->options(config('option.radio_option'))->default(2);
                $form->radio('is_foreign')->options(config('option.radio_option'))->default(2);
                $form->radio('is_married')->options(config('option.married_option'))->default(2);
                $form->select('family_id')->options(Family::selector())->required();
            });

        });
    }
}
